﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;

namespace Brain
{
    public class DefaultEffect
    {
        public Effect Effect { get; protected set; }

        private EffectParameter world;
        private bool _world;
        public EffectParameter World
        {
            get
            {
                if (world == null && !_world)
                {
                    _world = true;
                    GetSemantic("world", out world);
                }
                return world;
            }
        }

        private EffectParameter view;
        private bool _view;
        public EffectParameter View
        {
            get
            {
                if (view == null && !_view)
                {
                    _view = true;
                    GetSemantic("view", out view);
                }
                return world;
            }
        }

        private EffectParameter projection;
        private bool _projection;
        public EffectParameter Projection
        {
            get
            {
                if (projection == null && !_projection)
                {
                    _projection = true;
                    GetSemantic("proection", out projection);
                }
                return world;
            }
        }

        protected void GetSemantic(string semantic, out EffectParameter parameter)
        {
            foreach (EffectParameter par in Effect.Parameters)
            {
                if (!string.IsNullOrEmpty(par.Semantic))
                {
                    if (par.Semantic.ToLower() == semantic)
                    {
                        parameter = par;
                        break;
                    }
                }
            }
            parameter = null;
        }

        public DefaultEffect(Effect fx)
        {
            this.Effect = fx;
        }
    }
}
